#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <list>

using namespace std;
typedef pair<int, int> PII;
const int N = 20;

int f[N][N];
int dist[N][N];
PII pre[N][N];
int n, m;
int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};

void bfs()
{
    dist[0][0] = 0;
    queue<PII> q;
    q.push({0, 0});
    while (q.size())
    {
        auto t = q.front();
        q.pop();
        for (int i = 0; i < 4; ++i)
        {
            int x = t.first + dx[i], y = t.second + dy[i];
            if (x >= 0 && x < n && y >= 0 && y < m && f[x][y] != 1 && dist[x][y] == -1)
            {
                dist[x][y] = dist[t.first][t.second] + 1;
                pre[x][y] = t;
                q.push({x, y});
            }
        }
    }

    int x = n - 1, y = m - 1;
    vector<PII> v;
    v.push_back({n - 1, m - 1});
    while (x || y)
    {
        auto t = pre[x][y];
        v.push_back({t.first, t.second});
        x = t.first, y = t.second;
    }

    reverse(v.begin(), v.end());

    for (int i = 0; i < v.size(); ++i)
    {
        printf("(%d %d)", v[i].first, v[i].second);
    }
}
int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            scanf("%d", &f[i][j]);
        }
    }
    memset(dist, -1, sizeof(dist));
    bfs();
    return 0;
}